#include "main.h"

sbit P3_1=P3^1;
sbit P3_2=P3^0;
sbit P3_3=P3^2;
sbit P3_4=P3^3;

int zhuangtai=0,k1=-1,k2=0,k3=0,k4=0,i=50,g=50,j=1,z=1,jishu=50;

void Timer0Init(void)		//1ºÁë@11.0592MHz
{
//	AUXR &= 0x7F;		//¶¨ʱƷʱ֓12Tģʽ
	TMOD &= 0xF0;		//ɨփ¶¨ʱƷģʽ
	TMOD |= 0x01;		//ɨփ¶¨ʱƷģʽ
	TMOD=0x01;
	TL0 = 0x66;		//ɨփ¶¨ʱ³õֵ
	TH0 = 0xFC;		//ɨփ¶¨ʱ³õֵ
	TF0 = 0;		//ǥ³ýTF0±ꖾ
	TR0 = 1;		//¶¨ʱƷ0¿ªʼ¼Ɗ±
	ET0=1;
	EA=1;
	PT0=0;
}

int main()
{
	Timer0Init();
	
	P3_1=P3_2=P3_3=P3_4=1;
	
	for(;j<=1000;j++)
		{
			Shumaguan(8,2);Delay(1); 
			Shumaguan(7,0);Delay(1); 
			Shumaguan(6,2);Delay(1); 
			Shumaguan(5,3);Delay(1); 
			Shumaguan(4,0);Delay(1); 
			Shumaguan(3,1);Delay(1); 
			Shumaguan(2,0);Delay(1); 
			Shumaguan(1,1);Delay(1); 	
		}
		
		zhuangtai=1;

	while (1)
	{
		Shumaguan(2,i%10);Delay(1);
		Shumaguan(3,i/10);Delay(1);
		Shumaguan(6,g%10);Delay(1);
		Shumaguan(7,g/10);Delay(1);	
		
		zhuangtai=1;
		
		if(((k1%2)==0)&&(zhuangtai==1))
		{
			for(;i>-1;i--)
			{
					for(j=1;j<=125;j++)
					{
							Shumaguan(2,i%10);Delay(1);
							Shumaguan(3,i/10);Delay(1);
							Shumaguan(6,i%10);Delay(1);
							Shumaguan(7,i/10);Delay(1);	
						
							 while((k1%2)==1)
										{
												Shumaguan(2,i%10);Delay(1);
												Shumaguan(3,i/10);Delay(1);
												Shumaguan(6,i%10);Delay(1);
												Shumaguan(7,i/10);Delay(1);						
										}						
					}
			}
			
			i=g;
			
			zhuangtai=0;
			
			for(j=1;j<=3;j++)
			{
				for(z=1;z<=63;z++)
				{
					Shumaguan(8,2);Delay(1); 
					Shumaguan(7,0);Delay(1); 
					Shumaguan(6,2);Delay(1); 
					Shumaguan(5,3);Delay(1); 
					Shumaguan(4,0);Delay(1); 
					Shumaguan(3,1);Delay(1); 
					Shumaguan(2,0);Delay(1); 
					Shumaguan(1,1);Delay(1); 						
				}
				
				P0=0x00;
				
				Delay(1000);
				
			}
			
			zhuangtai=1;
			
			k1=-1;			
			
		}
	}
}

	void zhongduanhanshu(void)  interrupt 1
{
	
	TL0 = 0x00;		//ɨփ¶¨ʱ³õֵ
	TH0 = 0xDC;		//ɨփ¶¨ʱ³õֵ
	
	if(zhuangtai==1)
	{
			P2_4=0 , P2_3=0 , P2_2=0 ;
			P0=0x0F;
			Delay(1);
		
			P2_4=0 , P2_3=1 , P2_2=1 ;
			P0=0x39;
			Delay(1);
		
			P2_4=1 , P2_3=0 , P2_2=0 ;
			P0=0x0F;
			Delay(1);
		
			P2_4=1 , P2_3=1 , P2_2=1 ;
			P0=0x39;
			Delay(1);		
	}
	
	if(P3_1==0)
		{
			Delay(5);while(!P3_1);Delay(5);k1++;
		}

		if((P3_2==0))
		{
			Delay(500);
			if((k1==-1)&&(zhuangtai==1))
			{
				g++;
				if(g>=99)
				{
					g=99;
				}
				k2++;
			}
			
			while(!P3_2)
			{
				Delay(500);
				if(k2==1)
				{
					if((k1==-1)&&(zhuangtai==1))
					{
						g+=9;
						if(g>=99)
						{
							g=99;
						}
						k2++;
					}
				}
				
				else
				{
				if((k1==-1)&&(zhuangtai==1))
				{
					g+=10;
					
					if(g>=99)
					{
						g=99;
					}
					k2++;
				}				
				}
				
					
			}
		k2=0;	
			
		}	
		
		if((P3_3==0))
		{
			Delay(200);
			
			if((k1==-1)&&(zhuangtai==1))
			{
				g--;
				
				if(g<=1)
				{
					g=1;
				}
				k3++;
			}
			
			while(!P3_3)
			{
				Delay(300);
				
				if(k3==1)
				{
					if((k1==-1)&&(zhuangtai==1))
					{
						g-=9;
						if(g<=1)
						{
							g=1;
						}
						k3++;
					}
				}
				
				else
				{
				if((k1==-1)&&(zhuangtai==1))
				{
					g-=10;
					
					if(g<=1)
					{
						g=1;
					}
					k3++;
				}				
				}
				
					
			}
			
		k3=0;	
		}	
		
		if(P3_4==0)
		{
			Delay(5);while(!P3_4);Delay(5);k4=1,k1=-1,i=g;
		}		
		

}